package com.example.websocket;

import io.micrometer.common.util.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author wwl
 * @version 1.0
 * @date 2024/8/26 14:24
 * @description:
 */
public class ParamUtil {
    /**
     * 将请求参数字符串转换成map
     */
    public static Map<String, String> parser(String queryString) {

        Map<String, String> map = new HashMap<>();
        if (StringUtils.isNotBlank(queryString)) {
            String[] params = queryString.split("&");
            for (String p : params) {
                String[] strs = p.split("=");
                if (strs.length == 2) {
                    map.put(strs[0], strs[1]);
                }
            }
        }
        return map;
    }

    public static void main(String[] args) {

        String text = "<#>BIGOLIVE 23453 验证码：345526，有效期10分钟。请勿分享。 HO9Fu1AtmTf";
        //Pattern p = Pattern.compile("\\b\\d{6}\\b");
        Pattern p = Pattern.compile("\\b\\d{4}\\b|\\b\\d{6}\\b");
        Matcher m = p.matcher(text);

        while (m.find()) {
            System.out.println(m.group());
        }

    }
}
